import { Controller, Get, HttpStatus, Query, Response } from '@nestjs/common';
import { MapService } from './map.service';
import { DecodeDto } from './dto';
import { ResultData } from 'src/common/utils/result';
import { Response as ResponseType } from 'express';

@Controller('map')
export class MapController {
  constructor(private readonly mapService: MapService) {}

  @Get('decode')
  async decode(@Query() decodeDto: DecodeDto) {
    const result = await this.mapService.decode(decodeDto);
    const status = result.status;
    if (status !== 0) {
      return ResultData.fail(HttpStatus.INTERNAL_SERVER_ERROR, result.message);
    }
    return ResultData.ok(result.result);
  }

  @Get('js-api-proxy')
  async jsApiProxy(@Response() res: ResponseType) {
    const result = await this.mapService.jsApiProxy();
    res.setHeader('Content-Type', 'text/javascript;charset=utf-8');
    res.send(result);
  }
}
